package com.qfedu.controller;

import com.qfedu.entity.Anonymity;
import com.qfedu.entity.ResponseData;
import com.qfedu.entity.User;
import com.qfedu.service.AnonymityService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class AnonymityController {
    @Autowired

    private AnonymityService anonymityService;
    @RequestMapping("/findAllAnonymity")
    //查询匿名投诉
    public ResponseData findAllAnonymity(int page,int limit){
        return anonymityService.findAllAnonymity(page, limit);
    }

    @RequestMapping("/addAnonymity")
    //增加匿名投诉
    public ResponseData addAnonymity(Anonymity anonymity, HttpServletRequest request){
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("loginUser");
        anonymity.setuNo(user.getNo());
        ResponseData responseData = new ResponseData();

        boolean result = anonymityService.addAnonymity(anonymity);

        if (result){
            responseData.setCode(ResponseData.SUCCESS_CODE);// 成功
            responseData.setMsg(ResponseData.SUCCESS_MSG);
        }else {
            responseData.setCode(ResponseData.FAIL_CODE);// 成功
            responseData.setMsg(ResponseData.FAIL_MSG);
        }
        return responseData;
    }
}
